package com.dx.financehy.utils;

import cn.hutool.core.bean.BeanUtil;

import java.util.List;
import java.util.stream.Collectors;
/**
 * <pre>
 * @描述：集合转换实体类
 * @作者：cxz
 * @创建时间：2023/07/26
 * </pre>
 **/
public final class BeansUtil {
    private BeansUtil() {
    }

    public static <T1, T2> List<T2> listCopy(List<T1> sourceList, Class<T2> clazz) {
        return (List) sourceList.stream().map((source)->{
            Object target;
            try {
                target = clazz.getDeclaredConstructor().newInstance();
            } catch (Exception e) {
                throw new RuntimeException();
            }
            BeanUtil.copyProperties(source, target);
            return target;
        }).collect(Collectors.toList());
    }

}
